
import 'package:anxin/config/string.dart';
import 'package:anxin/pages/GroupIndex.dart';
import 'package:anxin/pages/MeIndex.dart';
import 'package:anxin/pages/RecordIndex.dart';
import 'package:anxin/provide/CurrentIndexProvide.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provide/provide.dart';

import 'HomeIndex.dart';

class Index extends StatelessWidget
{

  List<BottomNavigationBarItem> bottomTabs = [
    BottomNavigationBarItem(
     title:Text( KString.homeTitle),
        activeIcon:new Image.asset('assets/images/home1.png'),
     icon: Image.asset('assets/images/home.png',fit: BoxFit.cover)
    ),
    BottomNavigationBarItem(
        title:Text( KString.group),
        activeIcon:new Image.asset('assets/images/chat1.png'),
        icon: Image.asset('assets/images/chat.png',fit: BoxFit.cover)
    ),
    BottomNavigationBarItem(
        title:Text( KString.record),
        activeIcon:new Image.asset('assets/images/record1.png'),
        icon: Image.asset('assets/images/record.png',fit: BoxFit.cover)
    ),
    BottomNavigationBarItem(
        title:Text( KString.mine),
        activeIcon:new Image.asset('assets/images/me1.png'),
        icon: Image.asset('assets/images/me.png',fit: BoxFit.cover)
    ),
  ];

  List<Widget> tabWidgets = [
    HomeIndex(),
    GroupIndex(),
    RecordIndex(),
    MeIndex()
  ];

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    ScreenUtil.instance = ScreenUtil(width:750,height:1344)..init(context);
    return Provide<CurrentIndexProvide>(
      builder: (context,child,val){
        //获取当前索引状态值
        int currentIndex = Provide.value<CurrentIndexProvide>(context).currentIndex;
        return Scaffold(
          backgroundColor:Color.fromRGBO(244, 245, 245, 1.0),
          bottomNavigationBar: BottomNavigationBar(
            selectedItemColor: Color(0xffff8635),
            unselectedItemColor: Color(0xff666666),
            type:BottomNavigationBarType.fixed,
            currentIndex: currentIndex,
            items:bottomTabs,
            onTap: (index){
              Provide.value<CurrentIndexProvide>(context).changeIndex(index);
            },
          ),
          body:IndexedStack(
            index: currentIndex,
            children: tabWidgets,
          )

        );

      }


    );
  }
  
}